Listing 1. List of the Environ$ function in WinWord Basic 'ENVIRON$ function for WinWord BASIC 'by Jonathan Zuck Declare Function GetDosEnvironment Lib "Kernel.EXE"() As Long Declare Function AnsiUpper$ Lib "User.EXE"(Seg As Integer, Addr As Integer) Function Environ$(Var$) Search$ = UCase$(Var$) 'Uppercase for easy comparisons SLen = Len(Search$) 'Save the length of the string Env = GetDosEnvironment 'Get a pointer to the E table Seg = Int(Env / 65536) + 1 'Calculate the segment Addr = - 2 'Fudge Addr so that, when added FLen = 2 'to Flen, it results in zero Success = 0 'Assume failure 'Loop until we have a match or no more variables While Left$(Found$, SLen) <> Search$ And FLen > 1 Addr = Addr + FLen 'Increment the pointer Found$ = AnsiUpper$(Seg, Addr) 'Convert LP to string FLen = Len(Found$) + 1 'Adjust for NULL Wend 'If we actually found a match, and not just the end of the table If FLen > 1 Then Offset = InStr(Found$, "=") + 1 'Find the data Environ$ = Right$(Found$, FLen - Offset) Else Environ$ = "" End If End Function Listing 2. A WinWord macro to test the Environ$ function Sub MAIN GetVar$ = UCase$(InputBox$("Environment Variable")) EnvVar$ = Environ$(GetVar$) If Len(EnvVar$) = 0 Then EnvVar$ = "Not Found!" MsgBox EnvVar$, GetVar$, 64 End Sub Listing 3: The case-sensitive Environ$ function Declare Function GetDosEnvironment Lib "KERNEL.EXE"() As Long Declare Sub LStrCpy Lib "Kernel.EXE"(Buff$, Seg As Integer, Addr As Integer) Function Environ$(Var$) Env = GetDosEnvironment Seg = Int(Env / 65536) + 1 Addr = - 2 Search$ = UCase$(Var$) SLen = Len(Search$) FLen = 2 Success = 0 Buff$ = String$(128, " ") While Left$(Found$, SLen) <> Search$ And FLen > 1 Addr = Addr + FLen LStrCpy(Buff$, Seg, Addr) Found$ = UCase$(Buff$) FLen = Len(Found$) + 1 Wend If FLen > 1 Then Offset = InStr(Found$, "=") + 1 Environ$ = Right$(Buff$, FLen - Offset) Else Environ$ = "" End If End Function